﻿using System;
using System.Windows;
using System.Windows.Controls;
using Mnk.Library.Common.Log;
using Mnk.Library.WpfControls.Components;

namespace HappyBa.Components
{
    /// <summary>
    /// Interaction logic for DescriptionView.xaml
    /// </summary>
    public partial class DescriptionView 
    {
        private readonly ILog log = LogManager.GetLogger<DescriptionView>();
        public DescriptionView()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty ValueProperty =
            DpHelper.Create<DescriptionView, string>("Value", " ", (s, v) => s.Value = v);
        public string Value
        {
            get { return (string) GetValue(ValueProperty); }
            set
            {
                SetValue(ValueProperty, value);
                try
                {
                    View.NavigateToString(Build(value ?? " "));
                }
                catch (Exception ex)
                {
                    log.Write(ex, "Invalid data");
                }
            }
        }

        private string Build(string text)
        {
            var str = string.Format("<style type=\"text/css\">.tau-clientinput table{{font-family: Arial;font-size: 12px;line-height: 15px;}}.tau-clientinput h1, .tau-clientinput h2, .tau-clientinput h3, .tau-clientinput h4, .tau-clientinput h5, .tau-clientinput h6 {{color: #103565;font-weight: bold;margin-bottom: 15px;margin-top: 0;}}.tau-clientinput h1 {{font-size: 20px;}}.tau-clientinput h2 {{font-size: 16px;}}.tau-clientinput h3 {{font-size: 14px;}}.tau-clientinput h4 {{font-size: 12px;}}.tau-clientinput h5 {{font-size: 10px;}}.tau-clientinput h6 {{font-size: 8px;}}.tau-clientinput a:link, .tau-clientinput a:hover {{color: #28428b;}}</style><div class=\"tau-clientinput\">{0}</div>",
                text.Replace(" ", "&nbsp;"));
            return str;
        }

    }
}
